package com.liws.hellofeiginclient.controller;

import com.liws.hellocommon.entity.Person;
import com.liws.hellofeiginclient.feigin.ProductClient;
import com.liws.hellofeiginclient.service.HystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: liweisheng
 * @Dcscription:
 * @Date: 2021/11/22 14:07
 */

@RestController
@RequestMapping("/hystrix")
public class HystrixController {


    @Autowired
    private HystrixService hystrixService;

    @RequestMapping(value = "/client/postHystrixByObject",method = RequestMethod.POST)
    public List<Person> postHystrixByObject(@RequestBody Person person){

        return hystrixService.postHystrixByObject(person);
    }

    /**
     *  不清楚该HystrixCache的作用
     * @param person
     * @return
     */
    @RequestMapping(value = "/client/postHystrixCacheByObject",method = RequestMethod.POST)
    public List<Person> postHystrixCacheByObject(@RequestBody Person person){
        hystrixService.postHystrixCacheByObject(person);

        hystrixService.updateProvider(person);

        return hystrixService.postHystrixCacheByObject(person);
    }



}
